package com.nbjtjc.safe.mapper.emg;

import com.nbjtjc.safe.model.emg.EmgPlanPublicGoods;
import com.nbjtjc.util.MyMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmgPlanPublicGoodsMapper extends MyMapper<EmgPlanPublicGoods> {

    @Delete("delete  from emg_plan_public_goods where plan_public_id=#{planPublicId}")
    int deleteByPlanPublicId(@Param("planPublicId") int planPublicId);


    @Select("SELECT emg_plan_public_goods.*,stock FROM emg_plan_public_goods " +
            "LEFT JOIN (SELECT sum(count) stock,goods_name FROM emg_goods GROUP BY emg_goods.goods_name ) gdt " +
            "ON emg_plan_public_goods.`name`=gdt.goods_name  " +
            "where emg_plan_public_goods.plan_public_id=#{planPublicId}")
    List<EmgPlanPublicGoods> findByPlanPublicId(int planPublicId);

    @Select("select emg_plan_public_goods.name from emg_plan_public_goods " +
            " where plan_public_id=#{planPublicId}")
    List<String> findGoodsNameByPlanPublicId(@Param("planPublicId") int planPublicId);
}